module FightersHelper

  def fighter_avatar_url(fighter)
    if fighter.present?
      if fighter.avatar_url(:thumb).present?
        fighter.avatar_url(:thumb).to_s
      else
        "default_fighter.png"
      end
    else
        "default_fighter.png"
    end
  end

  def fighter_poster_url(fighter)
    if fighter.present?
      if fighter.poster_url(:thumb).present?
        fighter.poster_url(:thumb).to_s
      else
        "default_fighter.png"
      end
    else
        "default_fighter.png"
    end
  end

  def age(dob)
    now = Time.now.utc.to_date
    now.year - dob.year - ((now.month > dob.month || (now.month == dob.month && now.day >= dob.day)) ? 0 : 1)
  end
  
end
